import { ref, onMounted, onUnmounted } from 'vue'
import { useEventListener } from './event'

// 鼠标位置事件
export function useMouse() {
  const x = ref(0)
  const y = ref(0)
  // let x = 0, y = 0

  function update(event) {
    x.value = event.pageX
    y.value = event.pageY
    // x = event.pageX
    // y = event.pageY
    // console.log(x, y);
  }

  // onMounted(() => window.addEventListener('mousemove', update))
  // onUnmounted(() => window.removeEventListener('mousemove', update))


  // 嵌套函数(抽离添加事件函数)
  useEventListener(window, 'mousemove', update)

  return { x, y }
}

// 初始化表格事件
export function useGetTableData(tableObj) {
  tableObj.loading = true
  setTimeout(() => {
    tableObj.tableData = [
      {
        date: "2016-05-03",
        name: "Tom",
        address: "No. 189, Grove St, Los Angeles",
      },
      {
        date: "2016-05-02",
        name: "Tom",
        address: "No. 189, Grove St, Los Angeles",
      },
      {
        date: "2016-05-04",
        name: "Tom",
        address: "No. 189, Grove St, Los Angeles",
      },
      {
        date: "2016-05-01",
        name: "Tom",
        address: "No. 189, Grove St, Los Angeles",
      },
    ]
    tableObj.loading = false
  }, 1000)
}